<script lang="tsx">
/**
 * 日常报销
 */
export default {
  name: "daily-reimburses"
}
</script>

<script lang="tsx" setup>
import {reactive, ref} from 'vue'
import {definePageModel, PageModel} from "@/frame/view/layout/page-model/constructor.ts"
import {getCode} from "@/utils/get-code.ts";
import {CodeRuleTypeEnum} from "@/utils/enum.ts";
import {processRequest} from "@/frame/apis/request";
import {ElMessage, ElMessageBox} from "element-plus";
/**
 * 定义emit
 */
const emit = defineEmits<{
  (e: "confirm"): void
}>()

/**
 * 下拉列表
 */
const reflections = reactive<{
  staffList: any[];
}>({
  staffList: []
})

/**
 * 获取员工列表
 */
const getStaffList = async () => {
  const result: any = await processRequest.get("/api/Staff", {
    IsEnable: true,
    currentPage: 1,
    pageSize: 9999
  })
  reflections.staffList = result.dataList
}

getStaffList()

/**
 * 页面配置
 */
const pageModelRef = ref()
const config = definePageModel<any>({
  url: "/api/DailyReimburses",
  searchForm: {
    els: [
      {
        eType: 'el-input',
        prop: "code",
        props: {
          placeholder: "单据编码",
          clearable: true
        }
      }, {
        eType: 'el-input',
        prop: "staff",
        props: {
          placeholder: "员工姓名",
          clearable: true
        }
      }, {
        eType: 'el-select',
        prop: "status",
        props: {
          placeholder: "审核状态",
          clearable: true
        },
        optionsData: {
          list: [
            {
              label: "待审核",
              value: 0
            },
            {
              label: "审核通过",
              value: 1
            },
            {
              label: "审核不通过",
              value: 2
            }
          ],
          label: "label",
          value: "value"
        }
      }
    ]
  },
  programForm: {
    els: [
      {
        label: "新增",
        eType: "el-button",
        props: {
          type: "primary"
        },
        event: "add"
      }
    ]
  },
  table: {
    page: {
      enable: true,
      pageSize: 20
    },
    props: {
      stripe: false,
      border: false
    },
    operation: {
      width: 100,
      props: {
        fixed: "right"
      },
      els: [
        {
          label: "编辑",
          eType: "el-button",
          props: {
            type: "primary",
            link: true
          },
          event: "edit"
        },
        {
          label: "删除",
          eType: "el-button",
          props: {
            type: "danger",
            link: true
          },
          event: "delete"
        }
      ]
    },
    els: [
      {
        label: "员工编码",
        prop: "staffCode",
        minWidth: 100
      },
      {
        label: "员工姓名",
        prop: "staffName",
        minWidth: 100
      },
      {
        label: "报销时间",
        prop: "reimburseTime",
        minWidth: 100
      },
      {
        label: "审核状态",
        prop: "status",
        minWidth: 100
      },
      {
        label: "未通过原因",
        prop: "unPassRemark",
        minWidth: 100
      },
      {
        label: "金额",
        prop: "amount",
        minWidth: 100
      },
      {
        label: "报销内容",
        prop: "content",
        minWidth: 100
      },
      {
        label: "报销凭证",
        prop: "file",
        minWidth: 100
      },
      {
        label: "备注",
        prop: "remark",
        minWidth: 100
      }
    ]
  },
  form: {
    title: "新增/编辑",
    width: 500,
    sheetForm: {
      async bindData(data: any) {
        if (!data.id) {
          data.code = await getCode(CodeRuleTypeEnum.日常报销表)
        }
        return data
      },
      labelWidth: "100px",
      els: [
        {
          label: "单据编码",
          eType: "el-input",
          prop: "code",
          renderFn(data: any) {
            return <span>{data.code}</span>
          }
        },
        {
          label: "员工名称",
          eType: "el-select",
          prop: "staffId",
          props: {
            placeholder: "请输入员工名称",
            clearable: true
          },
          optionsData: {
            reflect: "staffList",
            label: "name",
            value: "id"
          }
        },
        {
          label: "报销时间",
          eType: "el-date-picker",
          prop: "reimburseTime",
          props: {
            placeholder: "请输入报销时间",
            clearable: true,
            valueFormat: "YYYY-MM-DD"
          }
        },
        {
          label: "报销金额",
          eType: "el-input",
          prop: "amount",
          props: {
            placeholder: "请输入报销金额",
            clearable: true
          }
        },
        {
          label: "报销内容",
          eType: "el-input",
          prop: "content",
          props: {
            placeholder: "请输入报销内容",
            clearable: true
          }
        },
        {
          label: "报销凭证",
          eType: "el-upload",
          prop: "file",
          props: {
            action: "/development/anqin/api/Upload",
            limit: 1
          }
        },
        {
          label: "备注",
          eType: "el-input",
          prop: "remark",
          props: {
            placeholder: "请输入备注",
            clearable: true
          }
        }
      ]
    }
  }
})

/**
 * 新增
 */
const handleAdd = () => {
  pageModelRef.value.handleAdd()
}

/**
 * 编辑
 */
const handleEdit = (row: any) => {
  pageModelRef.value.handleEdit(row)
}

/**
 * 删除
 */
const handleDelete = (row: any) => {
  pageModelRef.value.handleDelete(row)
}

/**
 * 刷新
 */
const handleRefresh = () => {
  pageModelRef.value.refreshTableData()
}
</script>

<template>
  <PageModel ref="pageModelRef" :PageModel="config" :reflections="reflections" @add="handleAdd" @delete="handleDelete"
             @edit="handleEdit" @refresh="handleRefresh"
  />
</template>